global root "/Volumes/Workgroup/Lab/Lab-heimb/Montenovo/Volunteering Paper/Data"
global results "$root/07_results/RR/main"
global dictionaries "$root/Dictionaries"

/*
cd "$root"
use appended_analytic_010305111719, clear 

eststo extensive_margin: reghdfe whether_volunteer_person  taxprice post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children  religion rural, noabsorb vce(cluster state)

gen sample=e(sample) 
keep if sample==1
drop sample
bysort unique_id_crossys: egen max_tax_price_2016=max(taxprice) if year==2016
bysort unique_id_crossys: egen max_max_tax_price_2016=max(max_tax_price_2016) 

bysort unique_id_crossys: egen max_tax_price_2018=max(taxprice) if year==2018
bysort unique_id_crossys: egen max_max_tax_price_2018=max(max_tax_price_2018)

sort unique_id_crossys year 

gen diff_taxprice_2018_2016=.
replace diff_taxprice_2018_2016=max_max_tax_price_2018-max_max_tax_price_2016
tab diff_taxprice_2018_2016

sum diff_taxprice_2018_2016, d

gen adopt=.
replace adopt=2016

gen ysa=year-adopt
replace ysa=9999 if ysa==.

tab ysa, gen(ysa_)

gen abs_diff_taxprice_2018_2016=abs(diff_taxprice_2018_2016)


//gen treatm_group=0 if diff_taxprice_2018_2016==0
//gen treatm_group=0 if abs_diff_taxprice_2018_2016<=0.01

//replace treatm_group=1 if diff_taxprice_2018_2016>0.1
gen treatm_group=0 
replace treatm_group=1 if diff_taxprice_2018_2016>0.1

//alt: treated >0.1
//alt: treat group 1 if diff_taxprice_2018_2016>0.01 & treat group 2 if diff_taxprice_2018_2016<0.01
//alt: treat group 1 if diff_taxprice_2018_2016>0.1 & treat group 2 if diff_taxprice_2018_2016<0.1

keep if year>2015

gen post=0
replace post=1 if year==2018

gen post_treat=post*treatm_group

label var post_treat "Post x Treated"
label var post "Year 2018"
label var treat "Treated"

eststo extensive_01: reghdfe whether_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals


eststo intensive_01: reghdfe hours_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

drop treatm_group post_treat
gen treatm_group=0
replace treatm_group=1 if diff_taxprice_2018_2016>=0.25
gen post_treat=post*treatm_group
label var post_treat "Post x Treated"
label var post "Year 2018"
label var treat "Treated"

eststo extensive_025: reghdfe whether_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo intensive_025: reghdfe hours_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

drop treatm_group post_treat
gen treatm_group=0
replace treatm_group=1 if diff_taxprice_2018_2016>=0.28
gen post_treat=post*treatm_group
label var post_treat "Post x Treated"
label var post "Year 2018"
label var treat "Treated"

eststo extensive_028: reghdfe whether_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo intensive_028: reghdfe hours_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

cd "$results"

esttab extensive_01 extensive_025 extensive_028 using "extensive_DID.rtf", se star(* 0.10 ** 0.05 *** 0.01) replace se(a4) b(a3) title("Extensive Margin - Difference in Differences") addnotes("Outcome Variable: Whether person volunteered" "Col 1: Treated if Difference in Tax price between 2016 and 2018 is larger than 0.01" "Col 1: Treated if Difference in Tax price between 2016 and 2018 is larger or equal than 0.25" "Col 1: Treated if Difference in Tax price between 2016 and 2018 is larger than 0.28" "Year, State, Individual FE included") modelwidth(12) label cells(b(star fmt(3)) se(par fmt(3)))

esttab intensive_01 intensive_025 intensive_028 using "intensive_DID.rtf", se star(* 0.10 ** 0.05 *** 0.01) replace se(a4) b(a3) title("Intensive Margin - Difference in Differences") addnotes("Outcome Variable: Total hours the person volunteered" "Col 1: Treated if Difference in Tax price between 2016 and 2018 is larger than 0.01" "Col 1: Treated if Difference in Tax price between 2016 and 2018 is larger or equal than 0.25" "Col 1: Treated if Difference in Tax price between 2016 and 2018 is larger than 0.28" "Year, State, Individual FE included") modelwidth(12) label cells(b(star fmt(3)) se(par fmt(3)))
*/
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////


cd "$root"
use appended_analytic_010305111719, clear 

eststo extensive_margin: reghdfe whether_volunteer_person  taxprice post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children  religion rural, noabsorb vce(cluster state)

gen sample=e(sample) 
keep if sample==1
drop sample
bysort unique_id_crossys: egen max_tax_price_2016=max(taxprice) if year==2016
bysort unique_id_crossys: egen max_max_tax_price_2016=max(max_tax_price_2016) 

bysort unique_id_crossys: egen max_tax_price_2018=max(taxprice) if year==2018
bysort unique_id_crossys: egen max_max_tax_price_2018=max(max_tax_price_2018)

sort unique_id_crossys year 

gen diff_taxprice_2018_2016=.
replace diff_taxprice_2018_2016=max_max_tax_price_2018-max_max_tax_price_2016
tab diff_taxprice_2018_2016

sum diff_taxprice_2018_2016, d

gen abs_diff_taxprice_2018_2016=abs(diff_taxprice_2018_2016)

keep if year>2015

gen post=0
replace post=1 if year==2018
 
gen treatm_group=0 if max_max_tax_price_2018==1 & max_max_tax_price_2016==1
replace treatm_group=1 if (max_max_tax_price_2018!=. & max_max_tax_price_2016!=.) & (max_max_tax_price_2016!=1 | max_max_tax_price_2018!=1)
 
gen post_treat=post*treatm_group

label var post_treat "Post x Treated"
label var post "Year 2018"
label var treat "Treated"

eststo extensive_1: reghdfe whether_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

preserve
drop if hours_volunteer_person==0
eststo intensive_1: reghdfe hours_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals
restore


drop treatm_group post_treat
gen treatm_group=0 if diff_taxprice_2018_2016<=0.01
replace treatm_group=1 if diff_taxprice_2018_2016>0.1
gen post_treat=post*treatm_group
label var post_treat "Post x Treated"
label var post "Year 2018"
label var treat "Treated"

eststo extensive_01: reghdfe whether_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

preserve
drop if hours_volunteer_person==0
eststo intensive_01: reghdfe hours_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals
restore

drop treatm_group post_treat
gen treatm_group=0 if diff_taxprice_2018_2016<=0.01
replace treatm_group=1 if diff_taxprice_2018_2016>=0.25
gen post_treat=post*treatm_group
label var post_treat "Post x Treated"
label var post "Year 2018"
label var treat "Treated"

eststo extensive_025_control01: reghdfe whether_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

preserve
drop if hours_volunteer_person==0
eststo intensive_025_control01: reghdfe hours_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals
restore

drop treatm_group post_treat
gen treatm_group=0 if diff_taxprice_2018_2016<=0.01
replace treatm_group=1 if diff_taxprice_2018_2016>=0.28
gen post_treat=post*treatm_group
label var post_treat "Post x Treated"
label var post "Year 2018"
label var treat "Treated"

eststo extensive_028_control01: reghdfe whether_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

preserve
drop if hours_volunteer_person==0
eststo intensive_028_control01: reghdfe hours_volunteer_person treatm_group post post_treat post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state) noomitted
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals
restore 




cd "$results"

esttab extensive_1 extensive_01 extensive_025_control01 extensive_028_control01 using "extensive_DID_control01.rtf", se star(* 0.10 ** 0.05 *** 0.01) replace se(a4) b(a3) title("Extensive Margin - Difference in Differences") addnotes("Outcome Variable: Total hours the person volunteered" "Col 1: Treated if Tax price in 2016 or 2018 is not 1, Control if it is 1 in both years" "Col 2: Treated if Difference in Tax price between 2016 and 2018 is larger than 0.10" "Col 3: Treated if Difference in Tax price between 2016 and 2018 is larger or equal than 0.25" "Col 4: Treated if Difference in Tax price between 2016 and 2018 is larger than 0.28" "Control group in Columns 2, 3, and 4: Difference in Tax price between 2016 and 2018 is less than or equal to 0.01" "Year, State, Individual FE included") modelwidth(12) label cells(b(star fmt(3)) se(par fmt(3)))

esttab intensive_1 intensive_01 intensive_025_control01 intensive_028_control01 using "intensive_DID_control01.rtf", se star(* 0.10 ** 0.05 *** 0.01) replace se(a4) b(a3) title("Intensive Margin - Difference in Differences") addnotes("Outcome Variable: Total hours the person volunteered" "Col 1: Treated if Tax price in 2016 or 2018 is not 1, Control if it is 1 in both years" "Col 2: Treated if Difference in Tax price between 2016 and 2018 is larger than 0.10" "Col 3: Treated if Difference in Tax price between 2016 and 2018 is larger or equal than 0.25" "Col 4: Treated if Difference in Tax price between 2016 and 2018 is larger than 0.28" "Control group in Columns 2, 3, and 4: Difference in Tax price between 2016 and 2018 is less than or equal to 0.01" "Year, State, Individual FE included") modelwidth(12) label cells(b(star fmt(3)) se(par fmt(3)))

/*

foreach i in ysa_1 ysa_2 ysa_3 ysa_4 ysa_5 ysa_6  {
	generate treatm_group_`i'=`i'*treatm_group
}

reghdfe whether_volunteer_person treatm_group_ysa_1 treatm_group_ysa_2 treatm_group_ysa_3 treatm_group_ysa_4 treatm_group_ysa_6 post_tax_income hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state)


matrix define es = J(2,6,.)
forvalues j = 1(1)6{
	if `j' < 5 {
		matrix es[1,`j']= _b[treatm_group_ysa_`j'] 
		lincom _b[treatm_group_ysa_`j'] 
		matrix es[2,`j']=r(se)
							}
							
	else if `j'==5{
		matrix es[1,`j']= 0 
		matrix es[2,`j']=0
							}						
							
	else if `j'>5{
		matrix es[1,`j']= _b[treatm_group_ysa_`j'] 
		lincom _b[treatm_group_ysa_`j'] 
		matrix es[2,`j']=r(se)
							}
	
} 

matrix colnames es = -17 -15 -13 -7 -1 1  
matrix list es

cd "$results"
coefplot matrix(es[1]), se(es[2]) mlcolor(gray) lwidth(vthin)  lcolor(gray%70) recast(connected) ciopts(recast(rcap)) xline(18)  vertical omitted baselevels xtitle(Years Surrounding the TCJA) ytitle(Probability of Volunteering)
graph export event_study_extensive_margin.pdf, replace
